package GUI.Gestion;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTable;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

public class Panel_Categorias extends JPanel {
	private JTable tabla;
	private Panel_Categorias yo = this;
	private JButton btnAadirCategoria;
	private JButton btnBajaCategoria;
	private JButton btnModificarCategoria;
	private fachada_gestion fachada;
	

	/**
	 * Create the panel.
	 */
	public Panel_Categorias(JTable table,fachada_gestion fachada) {
		this.tabla = table;
		this.fachada = fachada;
		setLayout(new FormLayout(
				new ColumnSpec[] { ColumnSpec.decode("90dlu"), },
				new RowSpec[] { RowSpec.decode("31px"), RowSpec.decode("23px"),
						FormFactory.NARROW_LINE_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC, }));

		btnAadirCategoria = new JButton("A\u00F1adir Categoria");
		btnAadirCategoria.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				yo.fachada.DialogCate(yo, false);
			}
		});
		btnAadirCategoria.setAlignmentX(Component.CENTER_ALIGNMENT);
		add(btnAadirCategoria, "1, 1, fill, center");

		btnBajaCategoria = new JButton("Baja Categoria");
		btnBajaCategoria.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (yo.tabla.getSelectedRow() > 0) {
					Tabla modelo = (Tabla) yo.tabla.getModel();
					modelo.removeRow(yo.tabla.getSelectedRow());
					yo.tabla.setModel(modelo);
				}

			}
		});
		add(btnBajaCategoria, "1, 2, fill, fill");

		btnModificarCategoria = new JButton("Modificar Categoria");
		btnModificarCategoria.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (yo.tabla.getSelectedRow() > 0) {
					yo.fachada.DialogCate(yo,true);
				}
			}
		});
		add(btnModificarCategoria, "1, 4, fill, default");

	}

	public JTable getTabla() {
		return tabla;
	}

	public void setTabla(JTable tabla) {
		this.tabla = tabla;
	}

}
